 var idss = getvl1("id");
 
$(function(){
	 if(idss!=''){
	 	chaxun();
	 	$("#dingdanxiangqing").attr("href","39.0.0sell_dingdan_daituikuan_detail.html?id="+idss);
	 }else{
	 }
}); 

function  chaxun(){
     $.ajax({
			url: urlcore + "/api/refundOrder/selectOneDetails?orderid="+idss,
			type: "get",
			dataType: 'json',
			contentType: "application/json;charset=utf-8",
			success:function(data){
				if(data.success == true) {
					var da=data.data;
		var gmtDatetime = new Date(data.data.gmtDatetime).pattern("yyyy/MM/dd hh:mm");
	    var digndan='<div class="mid-width">'+
			'<span>订单状态</span>';
			if(da.order.status==8){
				digndan+='<em>等待卖家处理</em>';
			}else if(da.order.status==9){
				digndan+='<em>已完成</em>';
			}else if(da.order.status==10){
					digndan+='<em>已退款 </em>';
			}
		digndan+='</div>';
		$("#zhuangtai").append(digndan);
		var da=data.data;
		var dingdan='<div class="sell_detail_tui">'+
		'<span>买家名称</span>'+
		'<em>'+da.user.userName+'</em>'+
		'<a href="tel:'+da.user.phone+'">联系买家</a>'+
	'</div>'+
	'<ul>'+
		'<li>'+
			'<span>退款单号</span>'+
			'<em id="biao1">'+da.orderNumber+'</em>'+
			'<i class="copy">复制退款单号</i>'+
		'</li>'+
		'<li>'+
			'<span>操作时间</span>'+
			'<em>'+gmtDatetime+'</em>'+
		'</li>'+
		'<li>'+
			'<span>处理方式</span>';
			if(da.refundType==2){
				dingdan+='<em>申请退款</em>';
			}else{
				dingdan+='<em>退款退货</em>';
			}
			
			dingdan+=
		'</li>'+
		'<li>'+
			'<span>退款金额</span>'+
			'<em>'+da.refundMoney+'元</em>'+
		'</li>'+
		'<li>'+
			'<span>退款原因</span>'+
			'<em>'+da.refundReason+'</em>'+
		'</li>'+
		'<li>'+
			'<span>买家留言</span>'+
			'<em>'+da.refundRemark+'</em>'+
			'</li>'+
		'<div class="clearfix">'+
			'<span>凭证照片</span>';
			
			  var headImg=da.refundImg;
		 if(headImg != null && headImg != '') {
		var imgarr1 = headImg.split("***");
			$.each(imgarr1, function(y,n) {
				dingdan+='<img src="'+n+'" />';
			});
			}
		dingdan+='</div></ul>';
		$("#dingdanxinxi").append(dingdan);
		
		   var dingdans='<a href="39.0.0sell_dingdan_daituikuan_detail.html?id='+idss +'" id="dingdanxiangqing">原订单详情</a>'+
			'<a href="javascript:void(0);" name="1" id="'+da.order.id+'" onclick="tongyi(this)">拒绝退款</a>'+
			'<a href="javascript:void(0);" name="2" id="'+da.order.id+'" onclick="tongyi(this)" class="sell_detail_footer_curr">同意退款</a>';
		$("#dingdans").append(dingdans);
		
		$(function(){
			
			
 var copyBtn = document.querySelector('.copy')
  // 点击的时候调用 copyTextToClipboard() 方法就好了.
  copyBtn.onclick = function() {
  	var leirongs=$("#biao1").html();
    copyTextToClipboard(leirongs);
  }
    
  function copyTextToClipboard(text) {
   var textArea = document.createElement("textarea")
    textArea.style.position = 'fixed'
    textArea.style.top = 0
    textArea.style.left = 0
    textArea.style.width = '2em'
    textArea.style.height = '2em'
    textArea.style.padding = 0
    textArea.style.border = 'none'
    textArea.style.outline = 'none'
    textArea.style.boxShadow = 'none'
    textArea.style.background = 'transparent'
    textArea.value = text
    document.body.appendChild(textArea)
    textArea.select()
    try {
      var msg = document.execCommand('copy') ? '成功' : '失败'
      console.log('复制内容 ' + msg)
    } catch (err) {
      console.log('不能使用这种方法复制内容')
    }
  document.body.removeChild(textArea)
       }
	            
		});
		
			 }
			},
			error:function() {
				alert("error");
			}
		});

	
	
}




function tongyi(biaohaos){  //同意退款
	var oderis=$(biaohaos).attr("id");
	var odname=$(biaohaos).attr("name");
	var sts=8;
	if(odname==1){
		sts=9;
	}else if(odname==2){
		sts=10;
	}
	if(sts!=8){
   	  $.ajax({
      url: urlcore +"/api/refundOrder/auditRefund?orderId="+oderis+"&status="+sts,
			type: "get",
			dataType: 'json',
			contentType: "application/json;charset=utf-8",
			success: function(data) {
			window.location.href = "34.4.0sell_dingdan_daiqueren.html?id="+uuuuid;
			},
			error: function() {
				alert("error");
			}
		});
       	   } 
       	    
}

/*
function jujue(biaohaos){  //同意退款
   	  $.ajax({
      url: urlcore +" /api/refundOrder/auditRefund?orderId="+oderis+"&status=9",
			type: "get",
			dataType: 'json',
			contentType: "application/json;charset=utf-8",
			success: function(data) {
			window.location.href = "34.4.0sell_dingdan_daiqueren.html?id="+uuuuid;
			},
			error: function() {
				alert("error");
			}
		});

       	    
       	    
}
*/